<?php


require_once(dirname(__FILE__)."../../users/config.php");
require_once("kill.php");

$aid = isset($id) && is_numeric($id) ? $id : 0;
$cmobile= isset($cmobile) && is_numeric($cmobile) ? $cmobile : 0;
if(!defined('wwwew023com'))
{
ShowMsg("引入文件错误",'-1');
exit();
	
}


if($aid=='0' or $cmobile=='0')
{
ShowMsg("参数错误车型不存在",'-1');
exit();
	
}

if($_COOKIE['buydd']=='188_'.$aid.'ZC')
{
ShowMsg("您已经预定成功，请不要重复刷新",'-1');
exit();
	
}

$contact_mobile=$cmobile;
$contact_name=$crealname;
$contact_phone=$ctel;
$contact_email=$cemail;
$order_comment=$cmessage;
$totalPrice=$totalprice;
$AdultNum=$txtComeDate;
$KidNum=$txtOutDate;
$time=time();
$ip=getip();
	
$buyid = '188_'.$aid.'ZC'.mt_rand(1,99);

if(!$cfg_ml->IsLogin())
{ //如果没有登录

        
        
	    $row = $dsql->GetOne("Select mid From `#@__member` where mb='$contact_mobile' ");
		if(!is_array($row))
		{ //如果手机号码没有注册，则注册
		$rrss='Y';
		$jointime = time();
		$joinip = GetIP();	
		$pwd = md5($contact_mobile);
		$inQuery2 = "INSERT INTO `#@__member` (`pwd` ,`rank` ,`money` ,`jointime`, `joinip` ,`logintime`,`loginip`,`checkmail`,`mb`,`tjr`,`tel`,`email`)
	   VALUES ('$pwd','10','0',
	   '$jointime','$joinip','$jointime','$joinip','$checkmail','$contact_mobile','$tjr','$contact_phone','$contact_email'); ";
	   
	   if(!$dsql->ExecuteNoneQuery($inQuery2))
		{
			$gerr = $dsql->GetError();
			ShowMsg("把数据保存到数据库时出错<br>error:{$gerr}，请联系管理员！","javascript:;");
			exit();	
		}
		
		//----------------------------------------------
		//模拟登录
		//---------------------------
			$cfg_ml = new MemberLogin(7*3600);
			$rs = $cfg_ml->CheckUser($contact_mobile, $contact_mobile);
			
		}
		
}



		$inquery = "INSERT INTO `#@__order`(title,id,mid,buyid,ip,time,name,mb,tel,mail,jj,jiage,cr,rt,fx,zc) Values('$title','$aid','".$cfg_ml->M_ID."','$buyid','$ip','$time','$contact_name','$contact_mobile','$contact_phone','$contact_email','$order_comment','$totalPrice','$AdultNum','$KidNum','$fx','1')";
		if(!$dsql->ExecuteNoneQuery($inquery))
		{
			$gerr = $dsql->GetError();
			ShowMsg("把数据保存到数据库时出错<br>error:{$gerr}，请联系管理员！","javascript:;");
			exit();
		}
		else
		{
		$pid='188_'.$aid.'zc';
		setcookie("buydd",$pid,time()+3600,"/");
		}


	


//$sql = "select * from #@__hotel where aid='$aid'";
//$dsql->SetQuery($sql);
//$dsql->Execute();
//$row = $dsql->GetArray();
$dpl = new DedeTemplate();
$tpl =$cfg_basedir.$cfg_templets_dir.'/default/188_order_hotel_2.htm';
$dpl->LoadTemplate($tpl);
$dpl->display();
	
?>